package com.tensquare.user.dao;

import com.tensquare.user.pojo.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface UserDao extends JpaRepository<User,String>,JpaSpecificationExecutor<User>{
    /**
     * 根据手机号查询用户
     * @param mobile
     * @return
     */
    public User findByMobile(String mobile);


    /**
     * 更新粉丝数
     * @param userid 用户ID
     * @param x 粉丝数
     */
    @Modifying
    @Query(value = "update tb_user u set u.fanscount=u.fanscount+? where u.id=?", nativeQuery = true)
    public void incFanscount(int x, String userid);

/**
 * 更新关注数
 * @param userid 用户ID
 * @param x 粉丝数
 */
    @Modifying
    @Query(value = "update tb_user u set u.followcount=u.followcount+? where u.id=?", nativeQuery = true)
     public void incFollowcount(int x, String userid);

}
